#include "stdafx.h"
#include "SyncObject.h"

CCritialSectionLock::CCritialSectionLock(LPCRITICAL_SECTION pCs)
{
  m_pCs = pCs;
  Lock();
}


CSleepObject::CSleepObject()
{
}

CSleepObject::~CSleepObject()
{
}

void CSleepObject::Init()
{
  ::InterlockedExchange(&m_lLockCount,1);
}

BOOL CSleepObject::Lock()
{
  LONG lInitVal;
  do
  {
    lInitVal = InterlockedCompareExchange(&m_lLockCount,0,1);
    ::Sleep(50);
  }while(lInitVal == 0);
  
  return TRUE;
}

BOOL CSleepObject::Unlock()
{
  ::InterlockedExchange(&m_lLockCount,1);
  return TRUE;
}
